package com.tss.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tss.pojo.Record;
import com.tss.pojo.Result;
import com.tss.service.RecordService;

@Controller
@RequestMapping("record")
public class RecordController {

	@Autowired
	 private RecordService recordService;
	
	@Autowired
	private HttpSession session;
	 
	/**
	 * 签到地址
	 * @param attendanceId
	 * @param studentId
	 * @return
	 */
	 @RequestMapping("signin/{attendanceId}")
	 @ResponseBody
	 public String signin(@PathVariable("attendanceId") Long attendanceId){
		 Record record = new Record();
		 record.setAttendanceId(attendanceId);
		 if(session.getAttribute("user_id")==null){
			 Result result = new Result();
			 result.setMessage("签到前请登录！");
			 result.setStatus(Result.STATUS_NO_LOGIN);
			 return result.toString();
		 }
		 record.setStudentId((Long) session.getAttribute("user_id"));
		 return recordService.addRecord(record).toString();
	 }
	 
	 
}
